//============================================================
// Producnt name:		Wz
// Version: 			1.0
// Coded by:			Wz (13066628480@163.com)
// Auto generated at: 	2016/10/9 10:22:04
//============================================================

using System;
using System.Collections.Generic;
using System.Text;
using Cloud.Model;
using System.Data.SqlClient;
using System.Data;
namespace Cloud.DAL
{
	public static class USER_INFOService
	{
		#region SqlCommandText
		private const string Save_CommandText = "insert into USER_INFO values(@USER_ID,@USER_NAME,@ROLE_ID,@PASSWORD,@DEPARTMENT,@TEL,@ID_CODE,@EMAIL,@CREATE_TIME,@ENABLE,@SUPERVISER,@CLASS1,@CLASS2,@CLASS3)";
		private const string Update_CommandText = "Update USER_INFO set USER_NAME = @USER_NAME,ROLE_ID = @ROLE_ID,PASSWORD = @PASSWORD,DEPARTMENT = @DEPARTMENT,TEL = @TEL,ID_CODE = @ID_CODE,EMAIL = @EMAIL,CREATE_TIME = @CREATE_TIME,ENABLE = @ENABLE,SUPERVISER = @SUPERVISER,CLASS1 = @CLASS1,CLASS2 = @CLASS2,CLASS3 = @CLASS3 where USER_ID = @USER_ID";
		private const string Delete_CommandText = "delete from USER_INFO where USER_ID = @USER_ID";
		private const string FindAll_CommandText = "select * from USER_INFO";
		private const string FindById_CommandText = "select * from USER_INFO where USER_ID=@USER_ID";
		#endregion
		
		#region ??
		
		#endregion
		
		#region ??
		
		#endregion
		
		#region Save
		public static int Save(USER_INFO uSER_INFO)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@USER_ID",SqlDbType.VarChar),
				new SqlParameter("@USER_NAME",SqlDbType.VarChar),
				new SqlParameter("@ROLE_ID",SqlDbType.VarChar),
				new SqlParameter("@PASSWORD",SqlDbType.VarChar),
				new SqlParameter("@DEPARTMENT",SqlDbType.VarChar),
				new SqlParameter("@TEL",SqlDbType.VarChar),
				new SqlParameter("@ID_CODE",SqlDbType.VarChar),
				new SqlParameter("@EMAIL",SqlDbType.VarChar),
				new SqlParameter("@CREATE_TIME",SqlDbType.DateTime),
				new SqlParameter("@ENABLE",SqlDbType.VarChar),
				new SqlParameter("@SUPERVISER",SqlDbType.VarChar),
				new SqlParameter("@CLASS1",SqlDbType.VarChar),
				new SqlParameter("@CLASS2",SqlDbType.VarChar),
				new SqlParameter("@CLASS3",SqlDbType.VarChar)
				};
			pars[0].Value=uSER_INFO.USER_ID;
			pars[1].Value=uSER_INFO.USER_NAME;
			pars[2].Value=uSER_INFO.ROLE_ID;
			pars[3].Value=uSER_INFO.PASSWORD;
			pars[4].Value=uSER_INFO.DEPARTMENT;
			pars[5].Value=uSER_INFO.TEL;
			pars[6].Value=uSER_INFO.ID_CODE;
			pars[7].Value=uSER_INFO.EMAIL;
			pars[8].Value=uSER_INFO.CREATE_TIME;
			pars[9].Value=uSER_INFO.ENABLE;
			pars[10].Value=uSER_INFO.SUPERVISER;
			pars[11].Value=uSER_INFO.CLASS1;
			pars[12].Value=uSER_INFO.CLASS2;
			pars[13].Value=uSER_INFO.CLASS3;
	
			return DBHelper.ExecuteNonQuery(Save_CommandText,CommandType.Text,pars);
		}
		#endregion
		
		#region Update
		public static int Update(USER_INFO uSER_INFO)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@USER_ID",SqlDbType.VarChar),
				new SqlParameter("@USER_NAME",SqlDbType.VarChar),
				new SqlParameter("@ROLE_ID",SqlDbType.VarChar),
				new SqlParameter("@PASSWORD",SqlDbType.VarChar),
				new SqlParameter("@DEPARTMENT",SqlDbType.VarChar),
				new SqlParameter("@TEL",SqlDbType.VarChar),
				new SqlParameter("@ID_CODE",SqlDbType.VarChar),
				new SqlParameter("@EMAIL",SqlDbType.VarChar),
				new SqlParameter("@CREATE_TIME",SqlDbType.DateTime),
				new SqlParameter("@ENABLE",SqlDbType.VarChar),
				new SqlParameter("@SUPERVISER",SqlDbType.VarChar),
				new SqlParameter("@CLASS1",SqlDbType.VarChar),
				new SqlParameter("@CLASS2",SqlDbType.VarChar),
				new SqlParameter("@CLASS3",SqlDbType.VarChar)
				};
			pars[0].Value=uSER_INFO.USER_ID;
			pars[1].Value=uSER_INFO.USER_NAME;
			pars[2].Value=uSER_INFO.ROLE_ID;
			pars[3].Value=uSER_INFO.PASSWORD;
			pars[4].Value=uSER_INFO.DEPARTMENT;
			pars[5].Value=uSER_INFO.TEL;
			pars[6].Value=uSER_INFO.ID_CODE;
			pars[7].Value=uSER_INFO.EMAIL;
			pars[8].Value=uSER_INFO.CREATE_TIME;
			pars[9].Value=uSER_INFO.ENABLE;
			pars[10].Value=uSER_INFO.SUPERVISER;
			pars[11].Value=uSER_INFO.CLASS1;
			pars[12].Value=uSER_INFO.CLASS2;
			pars[13].Value=uSER_INFO.CLASS3;
	
			return DBHelper.ExecuteNonQuery(Update_CommandText,CommandType.Text,pars);
		}
		#endregion
		
		#region Delete
		public static int Delete(USER_INFO uSER_INFO)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@USER_ID",SqlDbType.VarChar)
				};
			pars[0].Value=uSER_INFO.USER_ID;
	
			return DBHelper.ExecuteNonQuery(Delete_CommandText,CommandType.Text,pars);
		}
		#endregion
		
		#region FindAll
		public static IList<USER_INFO> FindAll()
		{
			return CommonQuery(FindAll_CommandText,CommandType.Text,null);
		}
		#endregion
		
		#region FindById
		public static USER_INFO FindById(String uSER_ID)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@uSER_ID",SqlDbType.VarChar)
			};	
			pars[0].Value = uSER_ID;
			IList<USER_INFO> list = CommonQuery(FindById_CommandText,CommandType.Text,pars);
			return list.Count > 0 ? list[0] : null;
		}
		#endregion
		
		#region ??
		
		#endregion
		
		#region ??
		
		#endregion
		
		#region CommonQuery
		private static IList<USER_INFO> CommonQuery(string commandText, CommandType cmdType, SqlParameter[] pars)
		{
			IList<USER_INFO> list = new List<USER_INFO>();
			USER_INFO uSER_INFO = null;
			
			using (SqlDataReader reader = DBHelper.ExecuteQuery(commandText,cmdType,pars))
           	{
				while(reader.Read())
				{
					uSER_INFO = new USER_INFO();
                    if (reader["USER_ID"] == null)
                    {
                        uSER_INFO.USER_ID = "";
                    }
                    else
                    {
                        uSER_INFO.USER_ID = Convert.ToString(reader["USER_ID"]);
                    }
                    if (reader["USER_NAME"] == null)
                    {
                        uSER_INFO.USER_NAME = "";
                    }
                    else
                    {
                        uSER_INFO.USER_NAME = Convert.ToString(reader["USER_NAME"]);
                    }
                    if (reader["ROLE_ID"] == null)
                    {
                        uSER_INFO.ROLE_ID = "";
                    }
                    else
                    {
                        uSER_INFO.ROLE_ID = Convert.ToString(reader["ROLE_ID"]);
                    }
                    if (reader["PASSWORD"] == null)
                    {
                        uSER_INFO.PASSWORD = "";
                    }
                    else
                    {
                        uSER_INFO.PASSWORD = Convert.ToString(reader["PASSWORD"]);
                    }
                    if (reader["DEPARTMENT"] == null)
                    {
                        uSER_INFO.DEPARTMENT = "";
                    }
                    else
                    {
                        uSER_INFO.DEPARTMENT = Convert.ToString(reader["DEPARTMENT"]);
                    }
                    if (reader["TEL"] == null)
                    {
                        uSER_INFO.TEL = "";
                    }
                    else
                    {
                        uSER_INFO.TEL = Convert.ToString(reader["TEL"]);
                    }
                    if (reader["ID_CODE"] == null)
                    {
                        uSER_INFO.ID_CODE = "";
                    }
                    else
                    {
                        uSER_INFO.ID_CODE = Convert.ToString(reader["ID_CODE"]);
                    }
                    if (reader["EMAIL"] == null)
                    {
                        uSER_INFO.EMAIL = "";
                    }
                    else
                    {
                        uSER_INFO.EMAIL = Convert.ToString(reader["EMAIL"]);
                    }
                    if (reader["CREATE_TIME"] == null)
                    {
                        uSER_INFO.CREATE_TIME = new DateTime(1900,01,01,00,00,00);
                    }
                    else
                    {
                        uSER_INFO.CREATE_TIME = Convert.ToDateTime(reader["CREATE_TIME"]);
                    }
                    if (reader["ENABLE"] == null)
                    {
                        uSER_INFO.ENABLE ="";
                    }
                    else
                    {
                        uSER_INFO.ENABLE = Convert.ToString(reader["ENABLE"]);
                    }
                    if (reader["SUPERVISER"] == null)
                    {
                        uSER_INFO.SUPERVISER = "";
                    }
                    else
                    {
                        uSER_INFO.SUPERVISER = Convert.ToString(reader["SUPERVISER"]);
                    }
                    if (reader["CLASS1"] == null)
                    {
                        uSER_INFO.CLASS1 = "";
                    }
                    else
                    {
                        uSER_INFO.CLASS1 = Convert.ToString(reader["CLASS1"]);
                    }

                    if (reader["CLASS2"] == null)
                    {
                        uSER_INFO.CLASS2 = "";
                    }
                    else
                    {
                        uSER_INFO.CLASS2 = Convert.ToString(reader["CLASS2"]);
                    }

                    if (reader["CLASS3"] == null)
                    {
                        uSER_INFO.CLASS3 = "";
                    }
                    else
                    {
                        uSER_INFO.CLASS3 = Convert.ToString(reader["CLASS3"]);
                    }
					
					list.Add(uSER_INFO);
				}
            }
            return list;
		}
		#endregion
		
		#region ??
		
		#endregion
		
		#region ??
		
		#endregion


        #region Login
        private const string Login_Command = "select * from USER_INFO where USER_ID=@USER_ID and PASSWORD = @password";
        public static USER_INFO Login(String name, String pwd)
        {
            SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@uSER_ID",SqlDbType.VarChar),
				new SqlParameter("@password",SqlDbType.VarChar)
			};
            pars[0].Value = name;
            pars[1].Value = pwd;
            IList<USER_INFO> list = CommonQuery(Login_Command, CommandType.Text, pars);
            return list.Count > 0 ? list[0] : null;
        }
        #endregion
    }
}



